package org.rendao.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

public class ConfigurationService {

	@Autowired
	private NamedParameterJdbcTemplate jdbcTemplate;
	
	public void setJdbcTemplate(NamedParameterJdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	private Map<String, String> configMap;

	public Map<String, String> getConfigMap() {
		return configMap;
	}

	public void setConfigMap(Map<String, String> configMap) {
		this.configMap = configMap;
	}
	
	public void initConfigMap() {
		configMap = new HashMap<String, String>();
		String sql = "select key_field, value_field from config";
		List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new HashMap<String, Object>());
		for(Map<String, Object> config : list) {
			String key = config.get("key_field").toString();
			String value = config.get("value_field").toString();
			configMap.put(key, value);
		}
	}
	
	public void depositMap() {
		configMap.clear();
	}
	
	public final String FC_COLUMN3D_CAPTION = "FC_Column3D_Caption";
	public final String FC_COLUMN3D_XAXISNAME = "FC_Column3D_XAxisName";
	public final String FC_COLUMN3D_YAXISNAME = "FC_Column3D_YAxisName";
	
	public String getConfig(String key) {
		return configMap.get(key);
	}
}
